package com.hxqh.services;

import net.jctp.CThostFtdcTradingAccountField;
import net.jtrader.JTraderException;

import com.hxqh.bo.UserInfoTopBo;
import com.hxqh.services.constaints.ServiceConstains;
import com.hxqh.util.TradeUtilHelper;

public class UserInfoService {

	public UserInfoTopBo getUserInfoTop(String userId) throws JTraderException {
		TraderService tService = ServiceConstains.CTP_USER_TRADER_SERVICE_MAP.get(Integer.parseInt(userId));
		System.out.println(ServiceConstains.CTP_USER_TRADER_SERVICE_MAP.size());
		UserInfoTopBo bo = null;
		if(tService!=null) {
			CThostFtdcTradingAccountField f = tService.getTradingAccount();
			bo = new UserInfoTopBo();
			bo.setAvailable(TradeUtilHelper.floatValue(f.Available));
			bo.setCurrMargin(TradeUtilHelper.floatValue(f.CurrMargin));
			bo.setPositionProfit(TradeUtilHelper.floatValue(f.PositionProfit));
			bo.setAllMoney(TradeUtilHelper.floatValue(f.Available+f.CurrMargin+f.PositionProfit));
		}
		System.out.println("------------"+bo);
		return bo;
	}
}
